package com.yun.many.spec.exception;

import com.yun.many.spec.enums.IResultCode;
import com.yun.many.spec.utils.RequestUtils;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class BusinessException extends RuntimeException {

    /**
     * 结果code，系统异常[1000,2000)；业务异常 [3000,4000)；
     */
    private String code;

    /**
     * 调用链路UUID，可以用调用链中的tid，方便跟踪查问题
     */
    String traceId;

    public BusinessException(IResultCode code) {
        this(code.getCode(), code.getMsg(), null);
    }


    public BusinessException(IResultCode code, Throwable e) {
        this(code.getCode(), code.getMsg(), e);
    }

    public BusinessException(String code, String message) {
        this(code, message, null);
    }


    public BusinessException(String code, String message, Throwable e) {
        super(message, e);
        this.code = code;
        this.traceId = RequestUtils.getTraceId();
    }
}